<template>
  <div class="module-header">
    {{ `客户列表` }}
    <div class="module-header-search">
      物料编号或物料名称：
      <el-input size="default" v-model="bomCodeOrName" clearable placeholder="输入编号或物料名称"/>
      <el-button size="default" type="primary" @click="currentPage=1;getData()">搜索</el-button>
      <el-button size="default" type="primary" @click="dialogVisible = true">新增物料</el-button>
    </div>
  </div>
  <el-dialog v-model="dialogVisible" title="" width="30%" draggable>
    <span>It's a draggable Dialog</span>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">Cancel</el-button>
        <el-button type="primary" @click="dialogVisible = false">
          Confirm
        </el-button>
      </span>
    </template>
  </el-dialog>
  <div class="table-content">
    <el-table :data="bomList" style="width: 100%" stripe empty-text="没有数据">
      <el-table-column prop="code" label="物料编码" width="80"></el-table-column>
      <el-table-column prop="name" label="物料名称" width="360"></el-table-column>
      <el-table-column prop="unit" label="物料单位" width="80"></el-table-column>
      <el-table-column prop="price" label="物料单价" width="80"></el-table-column>
      <el-table-column prop="quantityPerRoll" label="卷料容量" width="80"></el-table-column>
      <el-table-column prop="material" label="物料材质" width="140"></el-table-column>
      <el-table-column prop="customer" label="物料体系" width="80"></el-table-column>
      <el-table-column prop="description" label="物料备注"></el-table-column>
      <el-table-column label="管理" fixed="right" width="140">
        <template #default="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[10, 15, 20]"
                   background layout="prev, pager, next, sizes" small :total="recordCount" current-page="1"
                   :default-page-size="10"
                   @size-change="handleSizeChange" @current-change="handleCurrentChange"/>
  </div>
</template>

<script lang="ts">
import {Options, Vue} from 'vue-class-component';
import {getBom} from "@/apis/bom.api";
import BomModel from "@/models/BomModel";
import {BackendPageModel} from "@/models/BackendPageModel";

@Options({})
export default class MaterialView extends Vue {
  dialogVisible = false;
  currentPage = 1;
  pageSize = 10;
  recordCount = 0;
  bomCodeOrName = '';
  bomList: BomModel[] | null = null;

  created(): void {
    this.getData();
  }

  getData(): void {
    getBom(this.bomCodeOrName, this.currentPage, this.pageSize).then((value: BackendPageModel<BomModel>): void => {
      console.log(value)
      this.bomList = value.content
      this.recordCount = value.totalElements;
      console.log(this.bomList)
    })
  }

  handleEdit(rowIndex: number, row: BomModel): void {
    console.log(rowIndex, row)
  }

  handleDelete(rowIndex: number, row: BomModel): void {
    console.log(rowIndex, row)
  }

  handleCurrentChange(pageNo: number) {
    console.log(pageNo)
    this.getData();
  }

  handleSizeChange(pageSize: number) {
    console.log(pageSize)
    this.getData();
  }
}
</script>

<style scoped>
.module-header > .module-header-search {
  width: 540px;
}
</style>